<?php
// 我们的服务信息
class AboutAction extends Action {
	/*
	 * //域名查询结果有三个状态： //210：可以注册 //211：已经注册 //212：参数错误 //214：未知错误
	 */
	function  index2(){
		set_time_limit ( 0 );
		
		$letter = array (
				'a',
				'b',
				'c',
				'd',
				'e',
				'f',
				'g',
				'h',
				'i',
				'j',
				'k',
				'l',
				'm',
				'n',
				'o',
				'p',
				'q',
				'r',
				's',
				't',
				'u',
				'v',
				'w',
				'x',
				'y',
				'z',
				'0',
				'1',
				'2',
				'3',
				'4',
				'5',
				'6',
				'7',
				'8',
				'9'
		);

		$dao = M('domain');
		$data['deth'] = 3;
		foreach ($letter as $j1){
			foreach ($letter as $j2){
				foreach ($letter as $j3){
					$data['domain'] = $j1.$j2.$j3;
					$dao->add($data);
				}
			}
		}
		dump('over');
	}
	function index() {
		set_time_limit ( 0 );
		
		$letter = array (
				'a',
				'b',
				'c',
				'd',
				'e',
				'f',
				'g',
				'h',
				'i',
				'j',
				'k',
				'l',
				'm',
				'n',
				'o',
				'p',
				'q',
				'r',
				's',
				't',
				'u',
				'v',
				'w',
				'x',
				'y',
				'z',
				'0',
				'1',
				'2',
				'3',
				'4',
				'5',
				'6',
				'7',
				'8',
				'9' 
		);
		$map ['deth'] = $_GET ['deth'] ? $_GET ['deth'] : 1;
		if($map['deth']==4){
			dump('done');
			exit;
		}
		
		$id = $_GET ['id'] ? $_GET ['id'] : 0;
		$map ['id'] = array (
				'exp',
				'>' . $id 
		);
		
		if ($map ['deth'] == 1) {
			$list = $letter;
		} else {
			$list = M ( 'domain' )->where ( $map )->order ( 'id asc' )->limit ( 1000 )->select ();
			if (empty ( $list )) {
				dump('www');exit();
				$map ['deth'] += 1;
				$list = M ( 'domain' )->where ( $map )->order ( 'id asc' )->limit ( 1000 )->select ();
			}
		}
		
		$i = 0;
		foreach ( $list as $vo ) {
			for($j = 0; $j < 36; $j ++) {
				$i += 1;
				if ($map ['deth'] == 1) {
					$data [$i] ['domain'] = $vo . $letter [$j];
				} else {
					$data [$i] ['domain'] = $vo ['domain'] . $letter [$j];
				}
				$data [$i] ['deth'] = $map ['deth'] + 1;
			}
			
			$id = $vo ['id'];
		}
		
		$sql = "insert into wxh_domain (`domain`,`deth`) values ";
		foreach ($data as $vo){
			$sql .= "('$vo[domain]',$vo[deth]),";
		}
		$sql = rtrim($sql,',');
		
		$res = M()->execute($sql);
		dump($res);
		dump($sql);
		
		if($map['deth']==1){
			$map['deth'] = 2;
		}
		
		echo "<script type='text/javascript'>window.location.href='http://i/about/index/deth/".$map['deth']."/id/".$id."';</script>";
	}
	function getData(){
		$list = M('domain_ok')->field('domain')->select();
		foreach ($list as $var){
			if(preg_match('/\d+/',$var['domain'])){
				echo $var['domain'].'<br/>';
			}
		}
	}
	
	function test(){
		set_time_limit(0);
		$time = time();
		
		$id = $_GET ['id'] ? $_GET ['id'] : 0;
		$map ['id'] = array (
				'exp',
				'>' . $id
		);
		$map['status'] = array('exp','=0');
		$list = M('domain')->where($map)->order ( 'id asc' )->limit(10)->select();
		foreach ($list as $vo){
			$ids[] = $vo['id'];
		}
		$res = M('domain')->where(array('id'=>array('in', $ids)))->setField('status',1);
		dump($res);dump(M('domain')->getLastSql());
		//dump($list);exit;
		if(empty($list)){
			dump('over');
			exit;
		}
		
		foreach ($list as $vo){
			$domain = $vo['domain'].'.com';
			$t = time();
			$save['status'] = $this->query($domain);
			//dump('*******************');
			//dump(time()-$t);
			$where['id'] =$id = $vo['id'];
			M('domain')->where($where)->save($save);
			dump($domain.'====='.$save['status']);
		}
		
		//dump(time()-$time);
		//$time = time();
		
		//dump($id);
		//exit;
		echo "<script type='text/javascript'>window.location.href='http://192.168.1.100/about/test/id/".$id."';</script>";
		
	}
	
	// 查询接口
	function query($domain) {
		$do = "http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=" . $domain;
		$xml_data = file_get_contents ( $do );
		$xml_arr = ( array ) simplexml_load_string ( $xml_data );
		return $this->show ( $xml_arr );
	}
	// 显示接口
	function show($result_arr) {
		$returncode = $result_arr ['returncode'];
		$key = $result_arr ['key'];
		$original = $result_arr ['original'];
		$status = substr ( $original, 0, 3 );
		// 申明返回值
		return $status;
	}
}
?>